Fix build failure for dynamic file endpoints with trailingSlash "always"#17246
Fix build failure for dynamic file endpoints with trailingSlash "always"#17246astrobot-houston wants to merge 3 commits into
Conversation
…17241)\n\nOverride trailingSlash to 'never' in stringifyParams for endpoint routes\nwith file extensions, matching the route pattern generated by\ntrailingSlashForPath in create-manifest.ts. This fixes a regression from\n#17224 where dynamic file endpoints (e.g. [name].json.ts) with\ntrailingSlash: 'always' would fail to build with TypeError: Missing\nparameter."
🦋 Changeset detectedLatest commit: 4844547 The changes in this PR will be included in the next version bump. This PR includes changesets to release 395 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| // File endpoints (e.g. [name].json.ts) should never have a trailing slash, | ||
| // even when trailingSlash is set to 'always'. This matches the route pattern | ||
| // generated by trailingSlashForPath in create-manifest.ts. | ||
| const effectiveTrailingSlash = | ||
| route.type === 'endpoint' && hasFileExtension(route.route) ? 'never' : trailingSlash; |
There was a problem hiding this comment.
I don't like that we recompute this information. Since it's already computed, maybe we should pass it to downstream functions instead
There was a problem hiding this comment.
The bot doesn't read these, so if you want to change it you can just push to the PR.
There was a problem hiding this comment.
Yeah but what you think? Does it make sense? Is it possible? Asking for feedback
There was a problem hiding this comment.
Where else is it computed?
|
This issue has been blocking me to migrate to Astro v7, I went with passing |
Changes
[name].json.ts) no longer get a trailing slash appended during build whentrailingSlash: "always"is configured. This was causingTypeError: Missing parameterbecause the generated path/api/foo.json/didn't match the route's own regex pattern (which already used'never'for file endpoints after Fix trailing slash handling for dynamic file endpoints in dev mode #17224).stringifyParams: overridetrailingSlashto'never'when the route is an endpoint with a file extension, matching whattrailingSlashForPathproduces increate-manifest.ts.Closes #17241
Testing
packages/astro/test/units/routing/generator.test.ts:trailingSlash: 'always'produces path without trailing slashDocs
trailingSlash: "always"with file endpoints.